tools/ocaml/xenstored: do permission checks on xenstore root
authorEdwin Török <edvin.torok@citrix.com>
Tue, 15 Dec 2020 11:28:37 +0000 (12:28 +0100)
committerHans van Kranenburg <hans@knorrie.org>
Tue, 15 Dec 2020 11:28:37 +0000 (12:28 +0100)
commitdfb2b5f8cd2aefbe54448f29983c6c5d9c0e884c
treed2c7f54c53a1850cf63f7f54311240d37cd47844
parent44c568569ce85e9438743bbc9f69050b14e7defb
tools/ocaml/xenstored: do permission checks on xenstore root

This was lacking in a disappointing number of places.

The xenstore root node is treated differently from all other nodes, because it
doesn't have a parent, and mutation requires changing the parent.

Unfortunately this lead to open-coding the special case for root into every
single xenstore operation, and out of all the xenstore operations only read
did a permission check when handling the root node.

This means that an unprivileged guest can:

 * xenstore-chmod / to its liking and subsequently write new arbitrary nodes
   there (subject to quota)
 * xenstore-rm -r / deletes almost the entire xenstore tree (xenopsd quickly
   refills some, but you are left with a broken system)
 * DIRECTORY on / lists all children when called through python
   bindings (xenstore-ls stops at /local because it tries to list recursively)
 * get-perms on / works too, but that is just a minor information leak

Add the missing permission checks, but this should really be refactored to do
the root handling and permission checks on the node only once from a single
function, instead of getting it wrong nearly everywhere.

This is XSA-353.

Signed-off-by: Edwin Török <edvin.torok@citrix.com>
Acked-by: Christian Lindig <christian.lindig@citrix.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
tools/ocaml/xenstored/store.ml